package com.suanfa.collect;

/**
 * 等差数列的子集，长度大于等于3
 */
public class ArithmeticSlices {

    public int numberOfArithmeticSlices(int[] nums) {
       if(nums.length<3){
           return 0;
       }
       int d = nums[0]-nums[1];
       int ans = 0;
       int t = 0;
       for(int  i =2; i< nums.length; i++){
           if(nums[i-1]-nums[i] == d){
               t++;
           }else {
               d = nums[i-1]-nums[i];
               t=0;
           }
           ans +=t;
       }
       return  ans;

    }

}
